import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

path='chromedriver.exe'
browser=webdriver.Chrome(path)
# 最大化窗口
browser.maximize_window()
url='http://localhost:90/'
browser.get(url)
# 登陆
name=browser.find_element(By.XPATH,"//*[@id='username']")
name.send_keys('admin')
password=browser.find_element(By.XPATH,"//*[@id='password']")
password.send_keys('123456')
login=browser.find_element(By.XPATH,"//*[@id='login_btn']")
login.click()
# 进入零钱理财
WebDriverWait(browser,5,0.1).until(EC.presence_of_element_located((By.XPATH,"//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/a[1]")))
licai=browser.find_element(By.XPATH,"//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/a[1]")
licai.click()
WebDriverWait(browser,5,0.1).until(EC.presence_of_element_located((By.XPATH,"//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/ul[1]/li[1]/a[1]")))
lingqianlicai=browser.find_element(By.XPATH,"//*[@id='leftbaraside']/div[2]/nav[1]/ul[1]/li[3]/ul[1]/li[1]/a[1]")
lingqianlicai.click()
for i in range(20):
    WebDriverWait(browser, 5, 0.1).until(EC.presence_of_element_located((By.XPATH, "//*[@id='add_modal_btn']")))
    add = browser.find_element(By.XPATH, "//*[@id='add_modal_btn']")
    add.click()
    time.sleep(0.3)

    chanpin_name = browser.find_element(By.XPATH, "//*[@id='name_add_input']")
    chanpin_name.send_keys(f'测试产品{i}')
    # time.sleep(0.04)
    qirinianhuashouyi = browser.find_element(By.XPATH, "//*[@id='annualincome_add_input']")
    qirinianhuashouyi.send_keys(f'{i}')
    # time.sleep(0.04)
    wanyuanshouyi = browser.find_element(By.XPATH, "//*[@id='peiincome_add_input']")
    wanyuanshouyi.send_keys(f'{i}')
    # time.sleep(0.04)
    qitoujine = browser.find_element(By.XPATH, "//*[@id='invesmoney_add_input']")
    qitoujine.send_keys(f'{i}')
    # time.sleep(0.04)
    # baocun = browser.find_element(By.XPATH, "//*[@id='save_btn']")
    baocun=WebDriverWait(browser,5,0.1).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='save_btn']")))
    baocun.click()
    time.sleep(2)

